class Solution {
public:
    string path;
    vector<string> ret;
    int n;
    vector<string> letterCasePermutation(string s) {
        n=s.size();
        dfs(s,0);
        return ret;
    }

    void dfs(string& s,int pos)
    {
        if(pos==n)
        {
            ret.push_back(path);
            return;
        }

        if(s[pos]<'0'||s[pos]>'9')
        {
            path.push_back(s[pos]);
            dfs(s,pos+1);
            path.pop_back();
        }
        
        char x=s[pos];
        if(s[pos]>='a'&&s[pos]<='z')
            x-=32;
        else if(s[pos]>='A'&&s[pos]<='Z')
            x+=32;
        
        path.push_back(x);
        dfs(s,pos+1);
        path.pop_back();
    }
};
